﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InformationExtraction
{
    class Utils
    {
        public static int ProgressInterval = 100;

        public static void PrintTime(DateTime begin)
        {
            DateTime end = DateTime.Now;
            PrintTime(begin, end);
        }

        public static void PrintTime(DateTime begin, DateTime end)
        {
            Console.WriteLine("time (milliseconds): " + (end.Ticks - begin.Ticks) / 10000);
        }

        public static void PrintProgress(int i, bool forcePrint = false)
        {
            if (!forcePrint && i % ProgressInterval != 0)
                return;
            Console.SetCursorPosition(Console.CursorLeft - (i - ProgressInterval).ToString().Length, Console.CursorTop);
            Console.Write(i);
        }

        public static void PrintProgress(int i, int total, bool forcePrint = false)
        {
            if (!forcePrint && i % ProgressInterval != 0)
                return;
            string str = (i - ProgressInterval).ToString() + "/" + total.ToString();
            Console.SetCursorPosition(Console.CursorLeft - str.Length, Console.CursorTop);
            Console.Write(i + "/" + total);
        }

        public static void PrintProcessBegin(string title, string progressTitle)
        {
            Console.WriteLine(title);
            Console.Write(progressTitle + ": 0");
        }

        public static void PrintProcessBegin(string title, string progressTitle, int total)
        {
            Console.WriteLine(title);
            Console.Write(progressTitle + ": 0/" + total);
        }

        public static void PrintProcessEnd(DateTime begin, int i)
        {
            Utils.PrintProgress(i, true);
            Console.WriteLine();
            Utils.PrintTime(begin);
            Console.WriteLine();
        }

        public static void PrintProcessEnd(DateTime begin, int i, int total)
        {
            Utils.PrintProgress(i, total, true);
            Console.WriteLine();
            Utils.PrintTime(begin);
            Console.WriteLine();
        }
    }
}
